<?php

namespace App\Http\Controllers\Api;


use App\logic\OrderServer;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class OrderController extends BaseController
{
    /**
     * 生成订单
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function createOrder(Request $request)
    {
        try {
            $parasm = $request->all();

            $this->validate($request, [
                'uid' => 'required|numeric',
                'doctor_id' => 'required|numeric',
                'date' => 'required',
                'time' => 'required',
                'money' => 'required'
            ]);

            $parasm['type'] = 2;
            OrderServer::addOrder($parasm);
        } catch (\Exception $e) {
            return $this->witejson('30001', 'null', $e->getMessage());
        } catch (ValidationException $validationException) {
            return $this->witejson('30001', 'null', $validationException->getMessage());
        }
    }

    /**
     * 同步回调
     * @param Request $request
     */
    public function returnUrl(Request $request)
    {
        $parasm = $request->all();
        return $this->witejson('0', 'null', '操作成功');
    }

    public function notifyUrl(Request $request)
    {
        $parasm = $request->all();

    }

    public function text(Request $request)
    {
        $data = '{s:10:"gmt_create";s:19:"2023-05-25 20:36:54";s:7:"charset";s:5:"UTF-8";s:11:"gmt_payment";s:19:"2023-05-25 20:37:01";s:11:"notify_time";s:19:"2023-05-25 20:37:04";s:7:"subject";s:26:"fz202305252036480000000001";s:4:"sign";s:344:"vfzL3HppoTDjchLfMX+n2qa87DUK4r/nvhdkW7MVFkB+BiYIyhLWmxInnYQ5O1kJ00yhjJPb0K0+4HywAclF9cWHCCqofZyW5qUOzJIODqki+RpoqYd37p7JW1PzKZUXV7qhr+u0VASWD0I8dFb4MAYJPcWdUIaB9Hzck2yDxxgStAz8he6LFAMn0mK9pOHVaZTUTfS35hbqDHh5tAcmpKS5/cEFLGsriLTlEyVupnAcSO8+GmTn3WbaPB0Zj5hdPdLwBUHcKc5h+833TvkxDuZY7BDb6HrwpvhfBv1vnkBaWHxSCMBoxgDFLsga8i5UDoW2CnUicqslcqLR3dkyeQ==";s:8:"buyer_id";s:16:"2088722003366401";s:14:"invoice_amount";s:7:"1000.00";s:7:"version";s:3:"1.0";s:9:"notify_id";s:34:"2023052500222203703066400522466908";s:14:"fund_bill_list";s:52:"[{"amount":"1000.00","fundChannel":"ALIPAYACCOUNT"}]";s:11:"notify_type";s:17:"trade_status_sync";s:12:"out_trade_no";s:26:"fz202305252036480000000001";s:12:"total_amount";s:7:"1000.00";s:12:"trade_status";s:13:"TRADE_SUCCESS";s:8:"trade_no";s:28:"2023052522001466400501793109";s:11:"auth_app_id";s:16:"2021000121690743";s:14:"receipt_amount";s:7:"1000.00";s:12:"point_amount";s:4:"0.00";s:6:"app_id";s:16:"2021000121690743";s:16:"buyer_pay_amount";s:7:"1000.00";s:9:"sign_type";s:4:"RSA2";s:9:"seller_id";s:16:"2088621993878021";}';
        $arr = json_decode($data, true);
        dd($arr);
    }


}

